package aipay.mobile.activity;

import org.kobjects.util.Util;

import aipay.mobile.fragment.Utilities;
import aipay.mobile.library.SlidingMenuActivity;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class Home extends SlidingMenuActivity {
	
	private Float startx;
	private Boolean check = true;
	private ImageView menu;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		setLayoutIds(R.layout.menusliding, R.layout.home_activity);
		setAnimationDuration(300);
		setAnimationType(MENU_TYPE_SLIDEOVER);
		super.onCreate(savedInstanceState);
		Initilization();
		FragmentManager fm = getFragmentManager();
	      FragmentTransaction ft = fm.beginTransaction();
	      ft.add(R.id.home,new Utilities());
	      ft.commit();
	      menu.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				toggleMenu();
			}
		});
	}
	private void Initilization() {
		// TODO Auto-generated method stub
		menu = (ImageView) findViewById(R.id.menu);
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
	    switch (event.getAction()) {
	        case MotionEvent.ACTION_DOWN : {
	            startx= event.getX();
	            break ;           
	        }
	        case MotionEvent.ACTION_UP: {
	            float endY = event.getY();
	            if (endY > startx) {
	            	if(check){
	            		toggleMenu();
	            		check=!check;
	            	}
	            }
	            else {
	            	if (!check) {
	            		toggleMenu();
						check = !check;
					}
	            }
	        }
	    }
	    return true;
	}
}
